package com.example.administrator.fragarmentdemotest_a.fragarment_demo.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.administrator.fragarmentdemotest_a.R;
import com.example.administrator.fragarmentdemotest_a.fragarment_demo.Bean.FriendsBean;
//import com.example.administrator.fragarmentdemotest_a.utils.pic.GlideApp;

import java.util.List;

public class SubViewAdapter extends RecyclerView.Adapter<SubViewAdapter.SubViewHolder> {
    public List<FriendsBean> friends;

    public SubViewAdapter(List<FriendsBean> friends) {
        this.friends = friends;
    }

    @Override
    public SubViewAdapter.SubViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new SubViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_friend, parent, false));
    }

    @Override
    public void onBindViewHolder(SubViewAdapter.SubViewHolder holder, int position) {
        holder.setData(friends.get(position));
    }

    @Override
    public int getItemCount() {
        return friends.size();
    }

    public class SubViewHolder extends RecyclerView.ViewHolder {
        private ImageView fri_head;
        private TextView fri_name;

        private SubViewHolder(View itemView) {
            super(itemView);
            fri_head = itemView.findViewById(R.id.fri_head);
            fri_name = itemView.findViewById(R.id.fri_name);
        }

        public void setData(FriendsBean bean) {

            Glide.with(itemView.getContext()).load(bean.getHeadUrl()).into(fri_head);
            fri_name.setText(bean.getName());
        }
    }
}